namespace IAM.Interface.Model
{
    using IAM.Interface.Common;
    using IAM.Interface.Model.ENUM;
    using IAM.Interface.Model.Interface;
    using System;
    using System.Text;

    public class ExportData : AbstractConvertObject, IConvertXml
    {
        private string _appname = "";
        private ExportDataType _datatype = ExportDataType.IdentityUserList;
        private DateTime _exporttime = DateTime.Now;

        public override object ConvertToObject()
        {
            this.ExportTime = Convert.ToDateTime(this.CurrentXmlNode.Attributes["ExportTime"].InnerText);
            this.AppName = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["AppName"].InnerText);
            string dataType = this.CurrentXmlNode.Attributes["DataType"].InnerText.ToLower();
            if (dataType != null)
            {
                if (!(dataType == "identityuserlist"))
                {
                    if (dataType == "AuditFetch")
                    {
                        this.DataType = ExportDataType.AuditFetch;
                    }
                }
                else
                {
                    this.DataType = ExportDataType.IdentityUserList;
                }
            }
            return this;
        }

        public string AppName
        {
            get
            {
                return this._appname;
            }
            set
            {
                this._appname = value;
            }
        }

        public ExportDataType DataType
        {
            get
            {
                return this._datatype;
            }
            set
            {
                this._datatype = value;
            }
        }

        public DateTime ExportTime
        {
            get
            {
                return this._exporttime;
            }
            set
            {
                this._exporttime = value;
            }
        }

        public string XML
        {
            get
            {
                return (this.XMLBoday + this.XMLFinis);
            }
        }

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<ExportData");
                _xml.Append(" ExportTime=\"" + this.ExportTime.ToString() + "\"");
                _xml.Append(" AppName=\"" + EnDeCoding.Encode(this.AppName) + "\"");
                _xml.Append(" DataType=\"" + this.DataType.ToString() + "\"");
                _xml.Append(" >");
                return _xml.ToString();
            }
        }

        public string XMLFinis
        {
            get
            {
                return "</ExportData>";
            }
        }
    }
}
